/**
 * @auther zhonghuanting
 * @params args 传入参数（function）
 *         count 记录循环位
 *         comm 方法传入参数
 */
export function nextAll() {
    var args = arguments;
    var count = 0;
    var length = args.length;
    var comm = {};
    return new Promise((resolve, reject) => {
        if (args[count] && Object.prototype.toString.call(args[count]) == '[object Function]') {
            args[count](comm, nextFun)
        }

        function nextFun() {
            count++;
            const fn = args[count]
            if (count > length) {
                return;
            }
            if (fn && Object.prototype.toString.call(fn) == '[object Function]') {
                if ((length - 1) === count) {
                    resolve(fn(comm, nextFun))
                }
                fn(comm, nextFun)
            }
        }
    })
}


export function httpProcess() {
    var args = arguments;
    var count = 0;
    var length = args.length;
    var comm = args[length - 1];
    return new Promise((resolve, reject) => {
        if (args[count] && Object.prototype.toString.call(args[count]) == '[object Function]') {
            args[count](comm, nextFun)
        }
        function nextFun(params) {
            count++;
            const fn = args[count]
            if (count > length) {
                return;
            }
            if (fn && Object.prototype.toString.call(fn) == '[object Function]') {
                if (count === 2) {
                    resolve(fn(params, nextFun))
                }
                fn(comm, nextFun)
            }
        }
    })
}